﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 车牌识别系统1
{
    public partial class Form3 : Form
    {
        public static string id;
        public Form3()
        {
            InitializeComponent();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void Form3_Load(object sender, EventArgs e)
        {
            Random ran = new Random();
            label4.Text = ran.Next(10).ToString();
            label5.Text = ran.Next(10).ToString();
            label6.Text = ran.Next(10).ToString();
            label7.Text = ran.Next(10).ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string SqlStr = "server=.;database=cpsm;integrated security=SSPI";
            SqlConnection conn = new SqlConnection(SqlStr);
            conn.Open();
            string selectsql = "Select * from table_1 where userid ='" + textBox2.Text + "'and psw = '" + textBox1.Text + "'";
            SqlCommand comm = new SqlCommand(selectsql, conn);
            comm.CommandType = CommandType.Text;
            SqlDataReader sdr;
            sdr = comm.ExecuteReader();
            if (textBox3.Text == label4.Text + label5.Text + label6.Text + label7.Text)
            {
                if (sdr.Read())
                {
                    id = textBox1.Text;
                    Form6 f6 = new Form6();
                    f6.Show();
                    this.Hide();
                    return;
                }
                MessageBox.Show("用户名或密码不正确，不能进入系统", "非法用户");
                conn.Close();
                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                textBox1.Focus();

                Random ran = new Random();
                label4.Text = ran.Next(10).ToString();
                label5.Text = ran.Next(10).ToString();
                label6.Text = ran.Next(10).ToString();
                label7.Text = ran.Next(10).ToString();
            }
            else
                MessageBox.Show("验证码不正确，请重新输入", "验证", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            textBox1.Focus();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            textBox1.Focus();
            Random ran = new Random();
            label4.Text = ran.Next(10).ToString();
            label5.Text = ran.Next(10).ToString();
            label6.Text = ran.Next(10).ToString();
            label7.Text = ran.Next(10).ToString();
        }

        private void label8_Click(object sender, EventArgs e)
        {
            Random ran = new Random();
            label4.Text = ran.Next(10).ToString();
            label5.Text = ran.Next(10).ToString();
            label6.Text = ran.Next(10).ToString();
            label7.Text = ran.Next(10).ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Form1 f1 = new Form1();
            f1.Show();
            this.Hide();
        }

        private void label9_Click(object sender, EventArgs e)
        {
            Form4 f4 = new Form4();
            f4.Show();
            this.Hide(); 
        }
    }
}
